
// src/stores/connectionStore.ts
import { create } from 'zustand';
import { Connection } from '../api/types';

interface ConnectionStore {
  connections: Connection[];
  currentConnection: Connection | null;
  loading: boolean;

  setConnections: (connections: Connection[]) => void;
  setCurrentConnection: (connection: Connection | null) => void;
  addConnection: (connection: Connection) => void;
  removeConnection: (id: string) => void;
  setLoading: (loading: boolean) => void;
}

export const useConnectionStore = create<ConnectionStore>((set) => ({
  connections: [],
  currentConnection: null,
  loading: false,

  setConnections: (connections) => set({ connections }),
  
  setCurrentConnection: (connection) => set({ currentConnection: connection }),
  
  addConnection: (connection) =>
    set((state) => ({
      connections: [...state.connections, connection],
    })),
  
  removeConnection: (id) =>
    set((state) => ({
      connections: state.connections.filter((c) => c.id !== id),
    })),
  
  setLoading: (loading) => set({ loading }),
}));